import { Component, OnInit, ChangeDetectorRef } from "@angular/core";
import { FileUploader, FileItem, ParsedResponseHeaders } from "ng2-file-upload";
import { Config } from "../../service/config";
import {
  NzNotificationService,
  NzModalService,
  UploadFile
} from "ng-zorro-antd";
import {
  FormBuilder,
  FormGroup,
  Validators,
  FormControl
} from "@angular/forms";
import { HttpServcie } from "../../service/http.service";
import { UserCheckBean, PartyCheckBean } from "./bean/register.bean";
import { Router } from "@angular/router";
import * as moment from 'moment';

@Component({
  selector: "app-register",
  templateUrl: "./register.component.html",
  styleUrls: ["./register.component.scss"]
})
export class RegisterComponent implements OnInit {
  // 当有值是为true
  public openData:boolean=false;

  textFlag: boolean = true;
  _checked = true;
  modelTitle = "新增";
  validateForm: FormGroup; //个人
  validateForm2: FormGroup; //单位
  selectValue = "personal";
  x = "personal";
  config: any = Config;
  showImage: any = [];
  faceImage: any = [];
  _telephoneOne: string;
  _telephoneTwo: string;
  _useroptions: any = []; //用户类型
  _cardTypeoption: any = [];
  _industryoption: any = [];
  companyNameList : any = [];
  companyNamePep : string;
  partyList: any = []; //单位
  roleTypeList: any = []; //角色类型
  partyTypeList: any = Config.PARTY_TYPE;
  partyLevels : any = Config.PARTY_LEVEL;
  previewImage = "";
  previewVisible = false;
  nzSpinning = false;
  fileUploader = new FileUploader({
    url: Config.IP + Config.API.upload,
    method: "POST",
    itemAlias: "file",
    autoUpload: false,
    headers: [
      { name: "Authorization", value: "Bearer " + window.localStorage["token"] }
    ]
  });
  // 个人注册bean
  personalBean: UserCheckBean = new UserCheckBean();
  // 单位注册bean
  companyBean = new PartyCheckBean();
  //地址
  addresOptions: any;
  //省市区
  options: any = [];
  showWz = false;
  startList = [
    { value: "二星", label: "二星" },
    { value: "三星", label: "三星" },
    { value: "四星", label: "四星" },
    { value: "五星", label: "五星" }
  ];


  constructor(
    private _notification: NzNotificationService,
    private fb: FormBuilder,
    private httpServcie: HttpServcie,
    private router: Router,
    private modalService: NzModalService,
    public cd: ChangeDetectorRef,
  ) {
    if ((window.location.href + "").indexOf("wzscjg.hyjckj.net") >= 0) {
      this.showWz = true;
    }
    this.queryRole();
  }
  /**
   * 查询公司名称
  * */
  queryCompanyName(){
    if(this.companyNamePep ==null || this.companyNamePep==''){
      this._notification.create("warning", "警告提示", "请输入公司名称！");
      return;
    }
    this.httpServcie
      .queryCompanyNameList({companyNamePep:this.companyNamePep})
      .subscribe(data =>{
        if(data.status =="200"){
          this.partyList = data.data;
          if(this.partyList.length>0 && this.partyList !=null ){
            this.openData = true;
          }else{
            this.openData = false;
          }
          this.companyNamePep="";
          console.log(data.data)
        }  else {
          this._notification.create("error", "错误提示", data.message);
        }
      })
  }


  /**
   * 个人注册，去除系统管理员的角色
   */
  queryRole() {
    this.httpServcie
      .querySystemRoleList({ pageSize: 100, currentPage: 1 })
      .subscribe(data => {
        if (data.status == "200") {
          let list: [any] = data.data.list;
          list.forEach(element => {
            if (element.roleName != '超级管理员'
              && element.roleName != '使用系统管理员'
              && element.roleName != '维保系统管理员'
              && element.roleName != '检验系统管理员'
              && element.roleName != '监管系统管理员') {
              this._useroptions.push(element);
            }
          });
        }
      });
  }

  ChangeUnit(){
    //根据单位id 获取单位类型
    let partyType : string;
    if(this.personalBean.partyId !=null && this.personalBean.partyId !=undefined){
      this.httpServcie.partyQueryById({ id: this.personalBean.partyId })
        .subscribe(data => {
          if (data.status == 200) {
            partyType = data.data.partyType;
            this.httpServcie.registerRoleList(partyType).subscribe(data=>{
              if(data.status=='200'){
                this._useroptions = data.data;
              }
            });
          }else {
            console.log("register get unit fail !!");
          }
        });
    }
  }

  //选择单位
  partyListChange() {
    if (this.personalBean.partyId) {
      this.httpServcie
        .registRoleTypeList(this.personalBean.partyId)
        .subscribe(data => {
          if (data.status == "200") {
            this.roleTypeList = data.data;
          }
        });
    } else {
      this.roleTypeList = [{ roleTypeName: "请选择", id: "" }];
      this.personalBean.roleTypeId = "";
      this.roleTypeChange();
    }
  }

  //选择角色类型
  roleTypeChange() {
    if (this.personalBean.roleTypeId) {
      this.httpServcie
        .registerRoleList(this.personalBean.roleTypeId)
        .subscribe(data => {
          if (data.status == "200") {
            this._useroptions = data.data;
          }
        });
    } else {
      this._useroptions = [{ roleName: "请选择", id: "" }];
      this.personalBean.roleId = "";
    }
  }
  roleChange() {
    if (this.personalBean.roleId == '7') {
      this._cardTypeoption = [
        { value: "T", label: "T" },
        { value: "T1", label: "T1" },
        { value: "T2", label: "T2" }
      ];
    }
    if (this.personalBean.roleId == '5' || this.personalBean.roleId == '6') {
      this._cardTypeoption = [
        { value: "A4", label: "A4" },
        { value: "其他", label: "其他" }
      ];
    }
    if ( this.personalBean.roleId == '6') {
      this._cardTypeoption = [
        { value: "T3", label: "T3" },
        { value: "其他", label: "其他" }
      ];
    }
    if (this.personalBean.roleId == '3'
      || this.personalBean.roleId == '4'
      || this.personalBean.roleId == '18') {
      this._cardTypeoption = [
        { value: "监察A类", label: "监察A类" },
        { value: "监察B类", label: "监察B类" },
        { value: "监察协管员证", label: "监察协管员证" },
        { value: "其他", label: "其他" }
      ];
    }
    if (this.personalBean.roleId == '16') {
      this._cardTypeoption = [
        { value: "A1", label: "A1" },
        { value: "A2", label: "A2" },
        { value: "A4", label: "A4" },
        { value: "T3", label: "T3" },
        { value: "其他", label: "其他" }
      ];
    }

    if (this.personalBean.roleId == '17'){
      this._cardTypeoption = [
        { value: "T", label: "T" },
        { value: "T1", label: "T1" },
        { value: "T2", label: "T2" },
        { value: "其他", label: "其他" }
      ];
    }

    if (this.personalBean.roleId == '8') {
      this._cardTypeoption = [
        { value: "电梯检验员证", label: "电梯检验员证" },
        { value: "电梯检验师证", label: "电梯检验师证" }
      ];
    }
    if (this.personalBean.roleId == '19') {
      this._cardTypeoption = [
        { value: "电梯检验员证", label: "电梯检验员证" },
        { value: "电梯检验师证", label: "电梯检验师证" },
        { value: "其他", label: "其他" }
      ];
    }
  }

  //如果为办公人员、单位管理人员、电梯安全管理员 且证件类型为其它时，不必校验 证书编号，资质证书，取证时间
  cardTypeChange(){
    if ((this.personalBean.roleId == '10'|| this.personalBean.roleId == '11' || this.personalBean.roleId == '16' ||this.personalBean.roleId =='17' ||
         this.personalBean.roleId == '5'||this.personalBean.roleId == '18'||this.personalBean.roleId =='19') && this.personalBean.cardType == "其他") {
      this.textFlag = false;
    }else {
      this.textFlag = true;
    }
  }

  ngOnInit() {
    //查询单位
   /* this.httpServcie
      .queryListRegisterParty({ pageSize: 99999999, currentPage: 1 })
      .subscribe(data => {
        if (data.status == "200") {
          this.partyList = data.data.list;
        }
      });*/
    // this._useroptions = [
    //   { value: '', label: '请选择' },
    //   { value: '特种设备安全监察人员', label: '特种设备安全监察人员' },
    //   { value: '特种设备作业人员', label: '特种设备作业人员' },
    //   { value: '监管办公人员', label: '监管办公人员' },
    //   { value: '企业办公人员', label: '企业办公人员' },
    // ];

    this._cardTypeoption = [

    ];
    // { value: "", label: "请选择" },
    // { value: "A1", label: "A1" },
    // { value: "A2", label: "A2" },
    // { value: "A4", label: "A4" },
    // { value: "T1", label: "T1" },
    // { value: "T2", label: "T2" },
    // { value: "T3", label: "T3" },
    // { value: "监察A类", label: "监察A类" },
    // { value: "监察B类", label: "监察B类" },
    // { value: "监察协管员证", label: "监察协管员证" },
    // { value: "电梯检验员证", label: "电梯检验员证" },
    // { value: "电梯检验师证", label: "电梯检验师证" },
    // { value: "其他", label: "其他" }


    this._industryoption = [
      { value: "", label: "请选择" },
      { value: "信息传输", label: "信息传输" },
      { value: "软件", label: "软件" },
      { value: "信息技术服务业", label: "信息技术服务业" }
    ];
    this.validateForm = this.fb.group({
      userName: [null, [Validators.required, this.userNameCheck]], //用户姓名
      password: [null, [Validators.required]],
      checkPassword: [null, [Validators.required, this.confirmationValidator]],
      userCode: [null, [Validators.required]], //用户名
      roleType: [null, [Validators.required]], //用户类型
      cardType: [null, [Validators.nullValidator]], //用户持证类型
      cardTypeNumber: [null, [Validators.nullValidator]], //证件号
      cardNumber: [null, [Validators.required, this.cardNumberCheck]], //身份证号码
      partyId: [null, [Validators.required]], //单位全称
      mobile: [null, [Validators.nullValidator]], //办公电话
      email: [null, [Validators.required, this.emailCheck]], //E-mail
      agree: [null, [Validators.required]],
      // roleTypeId: [null, [Validators.required]], //角色所属类型
      roleId: [null, [Validators.required]], //角色
      phone: [null, [Validators.required, this.mobileCheck]], //手机号码
      firstgt: [null, [Validators.nullValidator]], //第一次取证时间
      companyNamePep: [null, [Validators.nullValidator]],
    });
    this.validateForm2 = this.fb.group({
      password: [null, [Validators.required]],
      checkPassword: [null, [Validators.required, this.confirmationValidator2]],
      userCode: [null, [Validators.required]], //用户名
      addresOptions: [null, [Validators.required]], //行政区划
      partyName: [null, [Validators.required]], //单位名称
      partyAddr: [null, [Validators.required]], //单位地址
      corporation: [null, [Validators.required]], //法人代表
      telephone: [null, [Validators.required]], //单位电话
      postalCode: [null, [Validators.required]], //邮政编码
      creditCode: [null, [Validators.required]], //组织机构代码
      businessLicenseNum: [null, [Validators.required]], //营业执照注册号
      contacts: [null, [Validators.required]], //联系人
      // industry: [null, [Validators.required]], //所属行业
      contactsWork: [null, [Validators.required]], //联系人职务
      // TODO 暂时封掉
      contactsCard: [null, [Validators.required, this.cardNumberCheck]], //联系人身份证号
      // contactsCard: [null, [Validators.nullValidator]], //联系人身份证号
      contactsPhone: [null, [Validators.required]], //联系人电话
      // TODO 暂时封掉
      // contactsEmile: [null, [Validators.required, this.emailCheck]], //联系人邮箱
      contactsEmile: [null, [Validators.nullValidator, this.emailCheck]], //联系人邮箱
      contactsMobile: [null, [Validators.required, this.mobileCheck]], //联系人手机
      contactsAddress: [null, [Validators.required]], //联系人地址
      agree: [null, [Validators.required]],
      partyType: [null, [Validators.required]],
      // partyLevel : [null, [Validators.required]],
      // zzzs: [null, [Validators.nullValidator]],  //资质证书
      zzdj: [null, [Validators.nullValidator]],  //资质等级
      maintStart: [null, [Validators.nullValidator]],
      // businessLicenseImg: [null, [Validators.required]],//组织机构代码证或营业执照
    });
    this.personalBean.fileList = [
      {
        uid: -1,
        name: 'person_exem_pic1.png',
        status: 'done',
        url: 'assets/images/person_exem_pic1.png'
      },
      {
        uid: -2,
        name: 'person_exem_pic2.png',
        status: 'done',
        url: 'assets/images/person_exem_pic2.png'
      }
    ];

    this.companyBean.zzzs = [
      {
        uid: -1,
        name: 'unit_exem_pic1.png',
        status: 'done',
        url: 'assets/images/unit_exem_pic1.png'
      },
      {
        uid: -2,
        name: 'unit_exem_pic.png',
        status: 'done',
        url: 'assets/images/unit_exem_pic.png'
      },

      ];
  }



  //用户姓名校验
  userNameCheck = (control: FormControl): { [s: string]: boolean } => {
    if (!control.value) {
      return {required: true};
    }else if (control.value){
      let reg =/^[\u4e00-\u9fa5]{2,5}$/;
      if (!reg.test(control.value)) {
        return { checkFormat: true, error: true };
      }
    }
  }

  // 身份证号码校验
  cardNumberCheck = (control: FormControl): { [s: string]: boolean } => {
    if (!control.value) {
      return { required: true };
    } else if (control.value) {
      let reg = /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
      if (!reg.test(control.value)) {
        return { checkFormat: true, error: true };
      }
    }
  };

  // 邮箱号码校验
  emailCheck = (control: FormControl): { [s: string]: boolean } => {
    if (!control.value) {
      return { required: true };
    } else if (control.value) {
      let reg = /^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/;
      if (!reg.test(control.value)) {
        return { checkEmail: true, error: true };
      }
    }
  };

  //手机号码校验
  mobileCheck = (control: FormControl): { [s: string]: boolean } => {
    if (!control.value) {
      return { required: true };
    } else if (control.value) {
      let reg = /^1[0-9]{10}$/;
      if (!reg.test(control.value)) {
        return { checkMobile: true, error: true };
      }
    }
  };
  confirmationValidator = (control: FormControl): { [s: string]: boolean } => {
    if (!control.value) {
      return { required: true };
    } else if (control.value !== this.validateForm.controls["password"].value) {
      return { confirm: true, error: true };
    }
  };

  confirmationValidator2 = (control: FormControl): { [s: string]: boolean } => {
    if (!control.value) {
      return { required: true };
    } else if (
      control.value !== this.validateForm2.controls["password"].value
    ) {
      return { confirm: true, error: true };
    }
  };

  updateConfirmValidator2() {
    /** wait for refresh value */
    setTimeout(_ => {
      this.validateForm2.controls["checkPassword"].updateValueAndValidity();
    });
  }

  updateConfirmValidator() {
    /** wait for refresh value */
    setTimeout(_ => {
      this.validateForm.controls["checkPassword"].updateValueAndValidity();
    });
  }

  getCaptcha(e: MouseEvent) {
    e.preventDefault();
  }

  //个人
  getFormControl(name) {
    return this.validateForm.controls[name];
  }
  //单位
  getFormControl2(name) {
    return this.validateForm2.controls[name];
  }
  // 选择注册个人/单位
  onchange(x) {
    console.log(x);
    this.selectValue = x;
  }

  //注册校验-个人
  _submitForm() {
    let param;
    document.getElementsByTagName('button').item(0).disabled = true;
    for (const i in this.validateForm.controls) {
      this.validateForm.controls[i].markAsDirty();
    }
    if (this.personalBean.cardType) {
      this.personalBean.cardType = this.personalBean.cardType.toString();
    }

    if (this.personalBean.roleId != '10' && this.personalBean.roleId != '11' && this.personalBean.roleId != '16' && this.personalBean.roleId != '17' &&
      this.personalBean.roleId != '5' && this.personalBean.roleId != '18' && this.personalBean.roleId != '19') {
      //不是 办公人员、管理人员  要校验 以下内容
      if (!this.personalBean.cardType) {
        this._notification.create("warning", "警告提示", "请选择持证类型");
        document.getElementsByTagName('button').item(0).disabled = false;
        return;
      }
      if (!this.personalBean.cardTypeNumber) {
        this._notification.create("warning", "警告提示", "请输入证件号码");
        document.getElementsByTagName('button').item(0).disabled = false;
        return;
      }
    }
    param = Object.assign({}, this.personalBean);
    param.fileList = [];
    param.faceUrl = null;
    param.signImg = null;
    // 初次取证判断
    if(param.firstgt !=null && param.firstgt !="" ){
      param.firstgt = moment(param.firstgt).format("YYYYMMDD");
    }
    if (this.personalBean.fileList.length) {
      let ret = Object.assign([], this.personalBean.fileList);
      ret.forEach(element => {
        if(element.uid != -1 && element.uid != -2){
          param.fileList.push(element["response"]["data"]);
        }
      });
      param.fileList = param.fileList.join(',');

      if (this.personalBean.roleId == '7') {
        if (param.fileList == null || param.fileList == "" || param.fileList == undefined) {
          this._notification.create("warning", "警告提示", "请上传资质文件");
          return;
        }
      }
      if (this.personalBean.roleId == '7') {
        if (param.firstgt == null || param.firstgt == "" || param.firstgt == undefined) {
          this._notification.create("warning", "警告提示", "请选择初次取证时间");
          document.getElementsByTagName('button').item(0).disabled = false;
          return;
        }
      }

    } else {
      param.fileList = null;
    }
    if (this.personalBean.faceUrl.length) {
      let ret = Object.assign([], this.personalBean.faceUrl);
      param.faceUrl = ret[0]["response"]["data"];
    }

    if(this.personalBean.signImg.length){
      let ret = Object.assign([],this.personalBean.signImg);
      param.signImg = ret[0]["response"]["data"];
    }

    if (this.personalBean.partyId == null || this.personalBean.partyId == '' || this.personalBean.partyId ==undefined ) {
      this._notification.create("warning", "警告提示", "请先通过搜索，选择单位名称");
      return;
    }
    this.nzSpinning = true;
    //提交


    this.httpServcie.userRegister(param).subscribe(
      data => {
        this.nzSpinning = false;
        // 异常
        if(this.personalBean.cardType !=null && this.personalBean.cardType !=undefined ){
          let splitlist = this.personalBean.cardType.split(",");
          this.personalBean.cardType = splitlist;
        }

        if (data.status != 200) {
          this._notification.create("error", "错误提示", data.message);
        } else {
          this._notification.create(
            "success",
            "提示",
            "注册成功, 审批完成后, 账号密码会发到您的邮箱"
          );
        }
        document.getElementsByTagName('button').item(0).disabled = false;
      },
      error => {
        this.nzSpinning = false;
        console.log(JSON.stringify(error));
      }
    );
  }
  //单位
  _submitForm2() {
    document.getElementsByTagName('button').item(0).disabled = true;
    let param;
    for (const i in this.validateForm2.controls) {
      this.validateForm2.controls[i].markAsDirty();
    }
    //处理是否提交
    for (const i in this.validateForm2.controls) {
      if (!this.validateForm2.controls[i].valid) {
        document.getElementsByTagName('button').item(0).disabled = false;
        return;
      }
    }

    if(this.companyBean.partyType == '4' && this.companyBean.partyLevel == null){
      this._notification.create("warning", "警告提示", "请输入监管单位级别");
    }

    if (this.addresOptions) {
      //省
      this.companyBean.partyProvince = this.addresOptions[0];
      //市
      this.companyBean.partyCity = this.addresOptions[1];
      //区
      this.companyBean.partyArea = this.addresOptions[2];
    }
    if (this.companyBean.partyType != 1) {
      this.companyBean.maintStart = null;
    }
    param = Object.assign({}, this.companyBean);
    param.zzzs = [];
    if (this.companyBean.zzzs.length > 0) {
      let ret = this.companyBean.zzzs;
      if(ret !=undefined){
        for(let i=0;i<ret.length;i++){
          if(ret[i].uid != "-1" && ret[i].uid != "-2"){
            param.zzzs.push(ret[i]["response"]["data"]);
          }
        }
      }
      param.zzzs = param.zzzs.join(',');
      if (!param.zzdj) {
        this._notification.create("warning", "警告提示", "请输入资质等级");
        document.getElementsByTagName('button').item(0).disabled = false;
        return;
      }
    } else {
      param.zzzs = null;
    }
    param.businessLicenseImg = null;
    if (
      this.companyBean.businessLicenseImg &&
      this.companyBean.businessLicenseImg.length > 0
    ) {
      let ret = Object.assign([], this.companyBean.businessLicenseImg);
      param.businessLicenseImg = ret[0]["response"]["data"];
    } else {
      // 暂时注掉，后面再打开  2018-08-06  盛赛荣
      this._notification.create("warning", "警告提示", "营业执照必须上传");
      document.getElementsByTagName('button').item(0).disabled = false;
      return;
    }

    this.nzSpinning = true;
    //提交
    this.httpServcie.partyRegister(param).subscribe(
      data => {
        this.nzSpinning = false;
        if (data.status != 200) {
          // 异常
          this._notification.create("error", "错误提示", data.message);
        } else {
          this._notification.create(
            "success",
            "提示",
            "注册成功, 审批完成后, 账号密码会发到您的邮箱"
          );
        }
        document.getElementsByTagName('button').item(1).disabled = false;
      },
      error => {
        this.nzSpinning = false;
        console.log(JSON.stringify(error));
      }
    );
  }

  loadData(e: {
    option: any;
    index: number;
    resolve: Function;
    reject: Function;
  }): void {
    if (e.index === -1) {
      e.resolve(this.httpServcie.getProvince());
      return;
    }
    const option = e.option;
    option.loading = true;
    if (e.index === 0) {
      let values: any = option["value"];
      let valueList = this.httpServcie.getCity(e.option);
      let cities: any = {};
      cities[values] = valueList;

      setTimeout(() => {
        option.loading = false;
        e.resolve(cities[option.value]);
      }, 1);
    }
    if (e.index === 1) {
      let value = option["value"];
      let valueList = this.httpServcie.getRelation(e.option);
      let scenicspots: any = {};
      scenicspots[value] = valueList;
      setTimeout(
        () => {
          option.loading = false;
          e.resolve(scenicspots[option.value]);
        },
        1,
        scenicspots,
        option
      );
    }
  }
  //点击用户协议弹出模态框
  showAgreement(elevatt, content, footer) {
    this.modelTitle = "用户协议";
    let currentModal = this.modalService.open({
      title: "用户协议",
      content: content,
      footer: footer,
      width: "86%",
      style: {
        top: "20px"
      },
      onOk() {
        console.log("Click ok");
      }
    });
  }
  // 移除图片
  nzRemoveFile = (file: UploadFile) => {
    let fileItem = file;
    if (fileItem["status"] == "removed") {
      if(fileItem.uid == "-1" || fileItem.uid == "-2"){
        this._notification.create("warning", "警告提示", "样本图片不能删除！");
      }
      if (fileItem["url"] && fileItem["url"].includes("http")) {
        this.deleteImg(fileItem.name);
      } else {
        this.deleteImg(fileItem["response"]["data"]);
      }
    }
  };
  // 删除图片服务
  deleteImg(filedata) {
    this.httpServcie.deleteUpload(filedata).subscribe(
      data => {
        let ret = data.data;
        if (data["status"] != "200") {
          this._notification.create("error", "错误提示", "删除失败！");
          return;
        }
        // 人脸设置
        // for (let i of this.personalBean.faceUrl) {
        //   if (i["response"]["data"].includes(ret)) {
        //     this.personalBean.faceUrl = [];
        //     return;
        //   }
        // }
        let list: UploadFile[] = [];
        let type = '0';
        //组织机构代码证或营业执照
        if(this.personalBean.fileList !=null && this.personalBean.fileList.length>0){
          for(let i=0;i<this.personalBean.fileList.length;i++){
            // 当有多个组织机构代码证或营业执照
            let dateFile = this.personalBean.fileList[i];
            // 样图不能删除
            if(dateFile.uid == "-1" || dateFile.uid == "-2"){
              continue;
            }
            if(dateFile["response"]["data"].includes(ret)){
              let index = this.personalBean.fileList.indexOf(dateFile);
              this.personalBean.fileList.splice(index, 1);
              this.personalBean.fileList = this.personalBean.fileList;
              list = this.personalBean.fileList;
              this.personalBean.fileList = [];
              type = '1';
            }
          }
        }
        if (type == '1') {
          list.forEach(element => {
            this.personalBean.fileList.push(element);
          })
        }

        // 组织机构代码证或营业执照
        for (let i of this.companyBean.businessLicenseImg) {
          if (i["response"]["data"].includes(ret)) {
            this.companyBean.businessLicenseImg = [];
            return;
          }
        }

        //单位资质文件 照片
        if(this.companyBean.zzzs !=null && this.companyBean.zzzs.length>0){
          for(let i=0;i<this.companyBean.zzzs.length;i++){
            // 获取单位资质文件
            let datezzzs = this.companyBean.zzzs[i];
            // 样图不能删除
            if(datezzzs.uid == "-1" || datezzzs.uid == "-2"){
                  continue;
            }
            if(datezzzs["response"]["data"].includes(ret)){
              let index = this.companyBean.zzzs.indexOf(this.companyBean.zzzs[i])
              this.companyBean.zzzs.splice(index, 1);
              this.companyBean.zzzs = this.companyBean.zzzs;
              list = this.companyBean.zzzs;
              this.companyBean.zzzs = [];
              type = '2';
            }
          }
        }
        if (type == '2') {
          list.forEach(element => {
            this.companyBean.zzzs.push(element);
          })
        }
        this.cd.detectChanges();
      },
      error => {
        this._notification.create("error", "错误提示", "请求超时！");
        return;
      }
    );
  }

  goLogin() {
    this.router.navigateByUrl("/login");
  }

  nzChange(event) {
    if (event.file.status == "error") {
      this._notification.blank("上传失败", `${event.file.message}`);
    }
    this.cd.detectChanges();
  }

  nzChange1(event) {
    if (event.file.status == "error") {
      this._notification.blank("上传失败", `${event.file.message}`);
    }
    this.cd.detectChanges();
  }

  // 预览图片
  handlePreview = (file: UploadFile) => {
    this.previewImage = file.url || file.thumbUrl;
    this.previewVisible = true;
  };
}
